aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts
blob: a6edf8b02d384ba276fc69c6a277e05d5d5eda75 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { auth, get } from "$lib/utils";
import { redirect } from "@sveltejs/kit";

export async function load({ cookies, params, parent }) {
  let { user } = await parent();
  let aid = cookies.get("aid");
  let { address } = params;
  let { balance } = await get(`/account/${aid}`, auth(cookies));

  try {
    let invoice = await get(`/invoice/${address}`);

    if (invoice) {
      let recipient = await get(`/users/${invoice.uid}`);
      if (recipient?.id !== user.id)
        redirect(307, `/pay/${recipient.username}`);
    }
  } catch (e) {
    // invoice not found
  }

  return { balance };
}